package sg.edu.nus.iss.phoenix.user.controller;

import java.io.IOException;
import java.util.List;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import sg.edu.nus.iss.phoenix.authenticate.delegate.AuthenticateDelegate;
import sg.edu.nus.iss.phoenix.core.controller.FCUtilities;
import sg.edu.nus.iss.phoenix.user.entity.User;
import sg.edu.nus.iss.phoenix.user.delegate.UserDelegate;

/**
 * Servlet implementation class ReviewSelectProducerPresenterController
 * @author Gayathri
 */
@WebServlet("/ReviewSelectProducerPresenterController/*")
public class ReviewSelectProducerPresenterController extends HttpServlet{
	
	
	private static final long serialVersionUID = 1L;
	
	
	    public ReviewSelectProducerPresenterController() {
	        // TODO Auto-generated constructor stub
	    }

		/**
		 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
		 */
		protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
			// TODO Auto-generated method stub
			processRequest(request, response);
		}

		/**
		 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
		 */
		protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
			// TODO Auto-generated method stub
			processRequest(request, response);
		}
		 /**
	     * Process requests from front controller. 
	     */
		 protected void processRequest(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
			 if (FCUtilities.stripPath(request.getPathInfo()).equalsIgnoreCase("presenter") ) {
				UserDelegate ur = new UserDelegate();
				List<User> presenterList = ur.getAllPresenters();
				request.getSession().setAttribute("presenterList", presenterList);
				RequestDispatcher rd = getServletContext().getRequestDispatcher("/pages/presenter.jsp");;
			    rd.forward(request, response);
			} else if (FCUtilities.stripPath(request.getPathInfo()).equalsIgnoreCase("producer")){
				
				UserDelegate ur = new UserDelegate();
				List<User> producerList = ur.getAllProducers();
				request.getSession().setAttribute("producerList", producerList);
				RequestDispatcher rd = getServletContext().getRequestDispatcher("/pages/producer.jsp");;
			    rd.forward(request, response);
				 
			}
			
		 }

}
